// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	8/6/2013 11:09:00 PM				
// -----------------------------

#include "LuaDataType.h"

#include "LuaClass.h"

namespace ObjectLua
{

	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<void>::push(Lua* lpLua, void* data)
	{
	}
	/*
	//	Get this data type from the stack
	*/
	void LuaDataType<void>::get(Lua* lpLua, int idx)
	{
	}

	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<int>::push(Lua* lpLua, int data)
	{
		lpLua->getStack()->pushInteger(data);
	}
	/*
	//	Get this data type from the stack
	*/
	int LuaDataType<int>::get(Lua* lpLua, int idx)
	{
		if(!lpLua->getStack()->isInteger(idx))
			lpLua->pushError("Expected 'int'");
		return lpLua->getStack()->getInteger(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<unsigned int>::push(Lua* lpLua, unsigned int data)
	{
		lpLua->getStack()->pushInteger((int) data);
	}
	/*
	//	Get this data type from the stack
	*/
	unsigned int LuaDataType<unsigned int>::get(Lua* lpLua, int idx)
	{
		if(!lpLua->getStack()->isInteger(idx))
			lpLua->pushError("Expected 'unsigned int'");
		return (unsigned int) lpLua->getStack()->getInteger(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<bool>::push(Lua* lpLua, bool data)
	{
		lpLua->getStack()->pushBool(data);
	}
	/*
	//	Get this data type from the stack
	*/
	bool LuaDataType<bool>::get(Lua* lpLua, int idx)
	{
		//if(!lpLua->getStack()->isBoolean(idx))
		//	lpLua->pushError("Expected 'bool'");
		return lpLua->getStack()->getBool(idx);
	}



	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<double>::push(Lua* lpLua, double data)
	{
		lpLua->getStack()->pushNumber(data);
	}
	/*
	//	Get this data type from the stack
	*/
	double LuaDataType<double>::get(Lua* lpLua, int idx)
	{		
		if(!lpLua->getStack()->isNumber(idx))
			lpLua->pushError("Expected 'double'");
		return lpLua->getStack()->getNumber(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<float>::push(Lua* lpLua, float data)
	{
		lpLua->getStack()->pushNumber((double) data);
	}
	/*
	//	Get this data type from the stack
	*/
	float LuaDataType<float>::get(Lua* lpLua, int idx)
	{		
		if(!lpLua->getStack()->isNumber(idx))
			lpLua->pushError("Expected 'float'");
		return (float) lpLua->getStack()->getNumber(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<char*>::push(Lua* lpLua, char* data)
	{
		lpLua->getStack()->pushString(data);
	}
	/*
	//	Get this data type from the stack
	*/
	char* LuaDataType<char*>::get(Lua* lpLua, int idx)
	{
		if(!lpLua->getStack()->isString(idx))
			lpLua->pushError("Expected 'char*'");
		return const_cast<char*>(lpLua->getStack()->getString(idx));
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<const int>::push(Lua* lpLua, const int data)
	{
		lpLua->getStack()->pushInteger(data);
	}
	/*
	//	Get this data type from the stack
	*/
	const int LuaDataType<const int>::get(Lua* lpLua, int idx)
	{
		if(!lpLua->getStack()->isInteger(idx))
			lpLua->pushError("Expected 'int'");
		return lpLua->getStack()->getInteger(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<const unsigned int>::push(Lua* lpLua, const unsigned int data)
	{
		lpLua->getStack()->pushInteger((const int) data);
	}
	/*
	//	Get this data type from the stack
	*/
	const unsigned int LuaDataType<const unsigned int>::get(Lua* lpLua, int idx)
	{
		if(!lpLua->getStack()->isInteger(idx))
			lpLua->pushError("Expected 'unsigned int'");
		return (const unsigned int) lpLua->getStack()->getInteger(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<const bool>::push(Lua* lpLua, const bool data)
	{
		lpLua->getStack()->pushBool(data);
	}
	/*
	//	Get this data type from the stack
	*/
	const bool LuaDataType<const bool>::get(Lua* lpLua, const int idx)
	{
		if(!lpLua->getStack()->isBoolean(idx))
			lpLua->pushError("Expected 'bool'");
		return lpLua->getStack()->getBool(idx);
	}



	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<const double>::push(Lua* lpLua, const double data)
	{
		lpLua->getStack()->pushNumber(data);
	}
	/*
	//	Get this data type from the stack
	*/
	const double LuaDataType<const double>::get(Lua* lpLua, int idx)
	{		
		if(!lpLua->getStack()->isNumber(idx))
			lpLua->pushError("Expected 'double'");
		return lpLua->getStack()->getNumber(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<const float>::push(Lua* lpLua, const float data)
	{
		lpLua->getStack()->pushNumber((const double) data);
	}
	/*
	//	Get this data type from the stack
	*/
	const float LuaDataType<const float>::get(Lua* lpLua, int idx)
	{		
		if(!lpLua->getStack()->isNumber(idx))
			lpLua->pushError("Expected 'float'");
		return (const float) lpLua->getStack()->getNumber(idx);
	}


	/*
	//	Push this data type onto the stack
	*/
	void LuaDataType<const char*>::push(Lua* lpLua, const char* data)
	{
		lpLua->getStack()->pushString(data);
	}
	/*
	//	Get this data type from the stack
	*/
	const char* LuaDataType<const char*>::get(Lua* lpLua, int idx)
	{		
		if(!lpLua->getStack()->isString(idx))
			lpLua->pushError("Expected 'const char*'");
		return lpLua->getStack()->getString(idx);
	}

}